package com.maxatime.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.maxatime.dao.CodeMapper;
import com.maxatime.dao.EmployeeInfoMapper;
import com.maxatime.dao.EmployeeRegisterMapper;
import com.maxatime.pojo.entity.Code;
import com.maxatime.pojo.entity.EmployeeInfo;
import com.maxatime.pojo.entity.EmployeeRegister;
import com.maxatime.service.LogonService;
import com.maxatime.util.MyContent;
import com.maxatime.util.PasswordManagerUtil;




@Service
public class LogonServiceImpl implements LogonService{
	
	@Autowired
	EmployeeInfoMapper employeeInfoMapper;
	
	@Autowired
	CodeMapper codeMapper;
	
	@Autowired
	EmployeeRegisterMapper employeeRegisterMapper;

	@Override
	public EmployeeRegister listData(String email,String password,String captcha) {
		// TODO Auto-generated method stub
		
		Map<String, Object> m = new HashMap<String, Object>();
		EmployeeRegister emplo=new EmployeeRegister();
		emplo.setEmail(email);
		emplo.setPassword(password);
		emplo.setCaptcha(captcha);
		String password1=PasswordManagerUtil.getMd5DigestAsHex(emplo.getPassword());
		emplo.setPassword(password1);
		
		EmployeeRegister employeeRegister1 =employeeRegisterMapper.cha(emplo);
		
		Code code=new Code();
		code.setEmail(email);
		code.setCaptcha(captcha);
		Code code1=codeMapper.cha(code);
		if(code1==null){
			m.put(MyContent.CODE, "9999");
			m.put(MyContent.MSG, "验证码错误，请重新输入");
		}
		
		
		
//		if(employeeRegister1!=null && code1!=null) {
//			
//			EmployeeInfo employeeInfo=new EmployeeInfo();
//			employeeInfo.setUserId(employeeRegister1.getUserId());
//			List<EmployeeInfo> list1=employeeInfoMapper.listData(employeeInfo);
//			m.put("grxx", list1.get(0));
//			m.put(MyContent.CODE, "0000");
//			m.put(MyContent.MSG, "登录成功");
//		}else if(code1==null){
//			m.put(MyContent.CODE, "9999");
//			m.put(MyContent.MSG, "验证码错误，请重新输入");
//		}else if(employeeRegister1==null) {
//			m.put(MyContent.CODE, "2222");
//			m.put(MyContent.MSG, "账号或密码错误，请重新输入");
//		}
		
		
		return employeeRegister1;
	}

//	@Override
//	public Map<String, Object> cha(Code record) {
//		// TODO Auto-generated method stub
//		
//		Code code=codeMapper.cha(record);
//		Map<String, Object> m = new HashMap<String, Object>();
//		
//		
//		if(code!=null) {
//			
//			m.put(MyContent.CODE, "0000");
//			m.put(MyContent.MSG, "登录成功");
//		}else{
//			m.put(MyContent.CODE, "6666");
//			m.put(MyContent.MSG, "验证码输入错误,请重新输入");
//			
//		}
//		
//		
//		
//		return m;
//	}

}
